package cn.liwq.demo.controller;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author lweiqiang
 * @date 2023/2/26
 */
@Slf4j
@RestController
@RequestMapping("/decimal")
public class DecimalController {

  @GetMapping("/path/{d}")
  public String pathDecimal(@PathVariable("d") BigDecimal d) {
    System.out.println(d);
    return d.toString();
  }

  @PostMapping("/form")
  public String formDecimal(DecimalDTO d) {
    System.out.println(d);
    return d.toString();
  }

  @PostMapping("/test")
  public Object test(@RequestBody DecimalDTO decimalDTO) {
    System.out.println(decimalDTO.getNumToBigDecimal());
    System.out.println(decimalDTO.getStrToBigDecimal());
    return decimalDTO;
  }

  @Data
  private static class DecimalDTO {

    private BigDecimal numToBigDecimal;

    private String strToBigDecimal;
  }
}
